
//Container(容器)这个组件用于路由权限判断的中转--->PrivateRoute.js(私有路由)中去判断
import React, { Component } from "react";
import { connect } from "react-redux";
import PrivateRoute from "./PrivateRoute";
import Mine from "../views/Mine";
import {  Toast } from "antd-mobile";
export class Container extends Component {
  // 将获取到的loginState通过属性的方式传递给PrivateRoute，然后PrivateRoute(私有路由)组件才能利用它去判断要跳转到哪里去
  render() {
    return (
      <PrivateRoute
        loginState={this.props.loginState}
        path="/mine"
        component={Mine}
      ></PrivateRoute>
    );
  }
}

// 创建映射函数读取redux中保存用户登录状态-当前用户是否已登录-false 则PrivateRoute组件内中判断跳转到login登录页
const mapStateToProps = (state) => {
  console.log(state.userModule.loginState, '当前用户是否已登录')
  if (!state.userModule.loginState) {
    Toast.fail("当前用户未登录!", 2);
  }
  return {
    loginState: state.userModule.loginState,
  };
};

export default connect(mapStateToProps)(Container);
